package org.ar.gameserver.login.service;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.ar.gameserver.common.exception.GameServerException;
import org.ar.gameserver.common.sql.JDBCTemplate;
import org.ar.gameserver.login.service.bean.UserRole;

public class UserLoginService {
	
	public List<UserRole> userLogin(Object[] objects) throws GameServerException {
		List<UserRole> list = null;
		try {
			StringBuffer sb = new StringBuffer();
			sb.append("SELECT TUR.* ");
			sb.append("  FROM TABLE_USER TU ");
			sb.append("  LEFT JOIN TABLE_USER_ROLE TUR ");
			sb.append("    ON TU.USER_ID = TUR.USER_ID ");
			sb.append(" WHERE TU.USER_NAME = ? ");
			sb.append("   AND TU.USER_PASSWORD = ? ");
			list = (List<UserRole>)JDBCTemplate.createQueryRunner().query(sb.toString(),new BeanListHandler(UserRole.class),objects);
		
			if(list.size() == 0) {
				throw new GameServerException("");
			}
			
		} catch (Exception e) {
			throw new GameServerException("", e);
		}
		return list;
	}
}
